// pages/personalMessage/personalMessage.js

const app = getApp();

Page({

  data: {
    userInfo: {},
    user: {}
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function () {
    let that = this;
    let token = wx.getStorageSync('token');
    let userInfo = wx.getStorageSync('user');
    this.setData({
      userInfo: userInfo
    })
    wx.request({
      url: 'http://localhost:3000/myhome/personalMessage',
      method: 'POST',
      data: {
        authorization: token
      },
      success: res => {
        console.log(res.data);
        that.setData({
          user: res.data.user
        })
      }
    })
  },
  submitPersonalMessage: function(e){
    let user = e.detail.value;
    let token = wx.getStorageSync('token');
    wx.request({
      url: 'http://localhost:3000/myhome/personalMessage/new',
      method: 'POST',
      // header: {
      //   authorization: token
      // },
      data: {
        user: user,
        authorization: token
      },
      success: res => {
        console.log(res.data)
        wx.showToast({
          title: '发布成功',
          icon: 'success',
          duration: 2000
        })

      }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})